# 包含搜索结果页+商品详情页
from idlelib.debugger_r import frametable

from selenium.webdriver.common.by import By

import config
from base.base_page import BuyerBasePage


class GoodsPage(BuyerBasePage):
    def __init__(self):
        super().__init__()
        # 商品名称
        self.goods_name=(By.XPATH,"//*[contains(text(),'{}')]")
        # 加入购物车
        self.add_cart_btn=(By.ID,"join_cart")
        # iframe标签
        self.frame=(By.CSS_SELECTOR,"[id*='layui-layer-iframe']")

    # 加入购物车
    def add_goods_cart(self):
        # 点击商品名词
        # self.find_el(self.goods_name).click()
        self.driver.find_element(self.goods_name[0],self.goods_name[1].format(config.GOODS_NAME))
        # 点击加入购物车
        self.find_el(self.add_cart_btn).click()
        # frame切换，调用父类切换frame的方法
        self.switch_frame(self.find_el(self.frame))